PLATFORM := $(shell uname)
ARCH = $(shell uname -m)
CC = g++ -g -Iinclude -I/usr/include/freetype2

#If linux
ifneq (, $(findstring Linux, $(PLATFORM)))
    ifneq (, $(findstring x86_64, $(ARCH)))
    	CC += -Wl,-rpath,lib64
	LIBS = -Llib64
    else
    	CC += -Wl,-rpath,lib
	LIBS = -Llib
    endif
        LIBS += -lsfml-graphics -lsfml-window -lsfml-system -lGLEW -lGLU -lfreetype -lftgl
	EXT = 
	DEFS =
endif

#If MacOSX
ifneq (, $(findstring Darwin, $(PLATFORM)))
        CC += -I/usr/X11/include/freetype2 -I/usr/X11/include -Ldylib -L/usr/X11/lib
	DEFS = -D MacOSX
        LIBS = -lsfml-graphics -lsfml-window -lsfml-system -framework OpenGL -framework GLUT -lftgl -lfreetype
	EXT = 
endif

LIBS +=
DEFS +=
OBJS = main.o Terrain.o Water.o MainWindow.o SkyBox.o Functions.o Model.o ModelInstance.o Grass.o GrassCluster.o Plane.o objLoader.o obj_parser.o list.o
TARGET = assign4

all: $(TARGET)$(EXT)
ifneq (, $(findstring Darwin, $(PLATFORM)))
	install_name_tool -change "@executable_path/../Frameworks/libsfml-graphics.2.dylib" "@executable_path/dylib/libsfml-graphics.2.dylib" $(TARGET)$(EXT)
	install_name_tool -change "@executable_path/../Frameworks/libsfml-window.2.dylib" "@executable_path/dylib/libsfml-window.2.dylib" $(TARGET)$(EXT)
	install_name_tool -change "@executable_path/../Frameworks/libsfml-system.2.dylib" "@executable_path/dylib/libsfml-system.2.dylib" $(TARGET)$(EXT)
	install_name_tool -change "/usr/local/lib/libftgl.2.dylib" "@executable_path/dylib/libftgl.2.dylib" $(TARGET)$(EXT)
endif

cleanbuild: clean all

$(TARGET)$(EXT): $(OBJS)
	$(CC) $(DEFS) -o $(TARGET)$(EXT) $(OBJS) $(LIBS)

main.o: src/main.cpp
	$(CC) -c src/main.cpp

MainWindow.o: src/MainWindow.cpp
	$(CC) -c src/MainWindow.cpp
	
Terrain.o: src/Terrain.cpp
	$(CC) -c src/Terrain.cpp

Water.o: src/Water.cpp
	$(CC) -c src/Water.cpp

SkyBox.o: src/SkyBox.cpp
	$(CC) -c src/SkyBox.cpp

Functions.o: src/Functions.cpp
	$(CC) -c src/Functions.cpp

Model.o: src/Model.cpp
	$(CC) -c src/Model.cpp

ModelInstance.o: src/ModelInstance.cpp
	$(CC) -c src/ModelInstance.cpp

Grass.o: src/Grass.cpp
	$(CC) -c src/Grass.cpp

GrassCluster.o: src/GrassCluster.cpp
	$(CC) -c src/GrassCluster.cpp

Plane.o: src/Plane.cpp
	$(CC) -c src/Plane.cpp

objLoader.o: src/objLoader.cpp
	$(CC) -c src/objLoader.cpp

obj_parser.o: src/obj_parser.cpp
	$(CC) -c src/obj_parser.cpp

list.o: src/list.cpp
	$(CC) -c src/list.cpp

clean:
	rm -f $(TARGET) $(OBJS)

cleanobjs:
	rm -f $(OBJS)
